package com.stox.charting.ui.swing.presenter.delegate.advisor;

import java.awt.Dimension;

import com.stox.charting.ui.swing.model.price.PriceChartView;
import com.stox.charting.ui.swing.view.ChartView;

public class ChartViewSizeAdvisor {

	private ChartSizeAdvisor chartSizeAdvisor;

	public void advise(ChartView chartView){
		if(chartView != null){
			chartView.setPreferredSize(chartView.getParent().getSize());
			if(chartView instanceof PriceChartView){
				PriceChartView priceChartView = (PriceChartView)chartView;
				int rangeSliderHeight = (int)priceChartView.getChartingInternalFrameView().getRangeSlider().getPreferredSize().getHeight();
				Dimension dimension = priceChartView.getPreferredSize();
				priceChartView.getContentPane().setPreferredSize(
						new Dimension((int)dimension.getWidth(), 
						(int)(dimension.getHeight() - rangeSliderHeight)));
			}
			for(int i = 0; i < chartView.getChartCount(); i++){
				chartSizeAdvisor.advise(chartView.getChart(i));
			}
		}
	}

	public ChartSizeAdvisor getChartSizeAdvisor() {
		return chartSizeAdvisor;
	}

	public void setChartSizeAdvisor(ChartSizeAdvisor chartSizeAdvisor) {
		this.chartSizeAdvisor = chartSizeAdvisor;
	}
	
}

